#pragma once
#include<iostream>
#include<cstdarg>
#include<cstdio>
#include<cstring>
#include<ctime>


//日志等级
#define DEBUG 0
#define NORMAL 1
#define WARNING 2
#define ERROR 3
#define FATAL 4

const char* gLevelMap[]{
    "DEGUG",
    "NORMAL",
    "WORNING",
    "ERROR",
    "FATAL"
};
// 完整的日志功能，至少: 日志等级 时间 支持用户自定义(日志内容, 文件行，文件名)
#define LOGFILE "./ReactorServer.log"
void logMessage(int level,const char* format,...)
{
    char stdBuffer[1024];
    int timestamp = time(nullptr);
    snprintf(stdBuffer,sizeof stdBuffer,"[%s] [%ld]",gLevelMap[level],timestamp);

    char logBuffer[1024];
    va_list vl;
    va_start(vl,format);
    vsnprintf(logBuffer,sizeof logBuffer,format,vl);
    va_end(vl);

    // FILE *fp = fopen(LOGFILE, "a");
    printf("%s%s\n", stdBuffer, logBuffer);
    // fprintf(fp, "%s%s\n", stdBuffer, logBuffer);
    // fclose(fp);

}